Rename the commands inside the hotplug scripts to match those used by hotplug
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Fri, 11 Nov 2005 17:01:44 +0000 (18:01 +0100)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Fri, 11 Nov 2005 17:01:44 +0000 (18:01 +0100)
and udev.  Pass all commands through from xen-backend.agent or
xen-backend.rules rather than second-guessing the individual scripts.  This
should make it easier to tear down devices cleanly, especially the dangling
vifs we are seeing at the moment.

Cope with a missing type node inside the block script, as we don't want to
resurrect a removed node by writing a hotplug error message.

Log failure of iptables command.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/examples/block
tools/examples/block-common.sh
tools/examples/vif-bridge
tools/examples/vif-common.sh
tools/examples/vif-nat
tools/examples/vif-route
tools/examples/xen-backend.agent
tools/examples/xen-backend.rules

index c5b6b6c215688bdaaf7e57df8bd67d58af30eca7..79636ac20aa5e2a2c4520883bd317810e8410a84 100644 (file)
@@ -3,6 +3,12 @@
 dir=$(dirname "$0")
 . "$dir/block-common.sh"
 
+case "$command" in
+    online | offline)
+        exit 0
+        ;;
+esac
+
 expand_dev() {
   local dev
   case $1 in
@@ -16,10 +22,10 @@ expand_dev() {
   echo -n $dev
 }
 
-t=$(xenstore_read "$XENBUS_PATH"/type || true)
+t=$(xenstore_read_default "$XENBUS_PATH"/type "MISSING")
 
 case "$command" in 
-  bind)
+  add)
     p=$(xenstore_read "$XENBUS_PATH"/params)
     case $t in 
       phy)
@@ -38,32 +44,25 @@ case "$command" in
        done
        exit 1
        ;;
-
-      *)
-        [ -x /etc/xen/scripts/block-"$t" ] && \
-           /etc/xen/scripts/block-"$t" bind $p
-       ;;
     esac
     ;;
 
-  unbind)
-    node=$(xenstore_read "$XENBUS_PATH"/node)
+  remove)
     case $t in 
       phy)
        exit 0
        ;;
 
       file)
+        node=$(xenstore_read "$XENBUS_PATH"/node)
        losetup -d $node
        exit 0
        ;;
-
-      *)
-        [ -x /etc/xen/scripts/block-"$t" ] && \
-           /etc/xen/scripts/block-"$t" unbind $node
-       ;;
-
     esac
     ;;
 
 esac
+
+# If we've reached here, $t is neither phy nor file, so fire a helper script.
+[ -x /etc/xen/scripts/block-"$t" ] && \
+  /etc/xen/scripts/block-"$t" "$command" $node
index 397f588c71de42ea353bc57cedf64539ae1ea85b..2e4683111177bb76ac6f44d7780ecf5dd860887a 100644 (file)
 dir=$(dirname "$0")
 . "$dir/xen-hotplug-common.sh"
 
-command="$1"
+findCommand "$@"
 
-if [ "$command" != "bind" ] && [ "$command" != "unbind" ]
+if [ "$command" != "online" ]  &&
+   [ "$command" != "offline" ] &&
+   [ "$command" != "add" ]     &&
+   [ "$command" != "remove" ]
 then
   log err "Invalid command: $command"
   exit 1
index d95d8ecef56b35341baea0af42e0c4da944facaa..c4bac8244ce8f24387f4862f35e0645dabbd149f 100755 (executable)
@@ -9,7 +9,7 @@
 # places, then this script is the default.
 #
 # Usage:
-# vif-bridge (up|down)
+# vif-bridge (add|remove|online|offline)
 #
 # Environment vars:
 # vif         vif interface name (required).
@@ -47,7 +47,7 @@ then
 fi
 
 case "$command" in
-    up)
+    online)
         if brctl show "$bridge" | grep "$vif" >&/dev/null
         then
           log debug "$vif already attached to $bridge"
@@ -58,9 +58,9 @@ case "$command" in
           fatal "brctl addif $bridge $vif failed"
 
         ifconfig "$vif" up || fatal "ifconfig $vif up failed"
-        success
         ;;
-    down)
+
+    remove)
         # vifs are auto-removed from bridge.
         ifconfig "$vif" down || fatal "ifconfig $vif down failed"
         ;;
@@ -69,3 +69,4 @@ esac
 handle_iptable
 
 log debug "Successful vif-bridge operation for $vif, bridge $bridge."
+success
index 273cbacab50fdbda29eb123dbb9ec0675c7f4e8f..c571b8d95b2da6c67c26f869463d6b854270d782 100644 (file)
@@ -22,12 +22,21 @@ dir=$(dirname "$0")
 
 findCommand "$@"
 
-if [ "$command" != "up" ] && [ "$command" != "down" ]
+if [ "$command" != "online" ]  &&
+   [ "$command" != "offline" ] &&
+   [ "$command" != "add" ]     &&
+   [ "$command" != "remove" ]
 then
   log err "Invalid command: $command"
   exit 1
 fi
 
+case "$command" in
+    add | offline)
+        exit 0
+        ;;
+esac
+
 
 # Parameters may be read from the environment, the command line arguments, and
 # the store, with overriding in that order.  The environment is given by the
@@ -46,7 +55,7 @@ vif="${vif:?}"
 
 function frob_iptable()
 {
-  if [ "$command" == "up" ]
+  if [ "$command" == "online" ]
   then
     local c="-A"
   else
index 9392f3d0ab2d941b32f22960ff065e61b2fb1472..8933285620461897f0409166c5a7bd6714ed5aff 100644 (file)
@@ -9,7 +9,7 @@
 # places, then vif-bridge is the default.
 #
 # Usage:
-# vif-nat (up|down)
+# vif-nat (add|remove|online|offline)
 #
 # Environment vars:
 # vif         vif interface name (required).
@@ -40,12 +40,12 @@ netmask=$netmask.$(( $intmask & 0x000000FF ))
 main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
 
 case "$command" in
-    up)
+    online)
         ifconfig ${vif} ${vif_ip} netmask ${netmask} up
         echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
         ipcmd='a'
         ;;
-    down)
+    remove)
         ifconfig ${vif} down
         ipcmd='d'
         ;;
index 7e640b22ff583849a87fa65ea75fcd2e1200bb42..21bc4b18d737f3e6cfd674c0aa1a03ac6f4d2f3b 100755 (executable)
@@ -9,7 +9,7 @@
 # places, then vif-bridge is the default.
 #
 # Usage:
-# vif-route (up|down)
+# vif-route (add|remove|online|offline)
 #
 # Environment vars:
 # vif         vif interface name (required).
@@ -26,12 +26,12 @@ dir=$(dirname "$0")
 main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
 
 case "$command" in
-    up)
+    online)
         ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up
         echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
         ipcmd='a'
         ;;
-    down)
+    remove)
         ifdown ${vif}
         ipcmd='d'
         ;;
index 35eb79601a48e73a8e3f7dd4fc6fc9ff62335004..dddcb3e8e3ab584496e9d3443261da38e4208cdc 100755 (executable)
@@ -2,35 +2,25 @@
 
 PATH=/etc/xen/scripts:$PATH
 
+case "$XENBUS_TYPE" in
+  vbd)
+    /etc/xen/scripts/block "$ACTION"
+    ;;
+  vif)
+    [ -n "$script" ] && $script "$ACTION"
+    ;;
+esac
+
 case "$ACTION" in
   add)
-    case "$XENBUS_TYPE" in
-      vbd)
-       /etc/xen/scripts/block bind
-        ;;
-    esac
     ;;
   remove)
-    case "$XENBUS_TYPE" in
-      vbd)
-       /etc/xen/scripts/block unbind
-        ;;
-      vif)
-        [ -n "$script" ] && $script down
-        ;;
-    esac
     # remove device backend store entries
-    xenstore-rm -t "$XENBUS_PATH"
-    xenstore-rm -t "error/$XENBUS_PATH"
+    xenstore-rm -t "$XENBUS_PATH"       || true
+    xenstore-rm -t "error/$XENBUS_PATH" || true
     ;;
   online)
-    case "$XENBUS_TYPE" in
-      vif)
-        [ -n "$script" ] && $script up
-        ;;
-    esac
     ;;
   offline)
     ;;
 esac
-
index 514768b13c0664776d696f62ed8d56edec4dd277..9c077660d1ef82f6bcc52b74626f1110c48e7f88 100644 (file)
@@ -1,4 +1,5 @@
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ACTION=="add", RUN+="/etc/xen/scripts/block bind"
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ACTION=="remove", RUN+="/etc/xen/scripts/block unbind"
-SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} up"
+SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online"
+SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline"
 SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t $env{XENBUS_PATH}"
+SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t error/$env{XENBUS_PATH}"